﻿using System;
using System.Collections.Generic;
using System.Text;
using TntOrm;
using TntOrm.Attributes;
using System.Data;

namespace SiteObjects
{
    [OrmTable( "USR_User", "Пользователи", true )]
    public class User : OrmDataBaseObject
    {
        private int? id_User;        
        private string _Name;        
        private string _Login;        
        private string _Password;        
        private string _XML;        
        private bool? _Approved;        
        private bool? _Deleted;        
        private DateTime? _DateCreated;
        private Role UserRole;

        #region Properties
        [OrmTableField( "id_User", SqlDbType.Int, false )]
        [OrmLookUp]
        [OrmPrimaryKey]
        public int? UserID
        {
            get { return this.id_User; }
            set { this.id_User = value; }
        }
        
        [OrmTableField( "id_Role", SqlDbType.Int, false )]
        [OrmLookUp]
        [OrmReference( typeof( Role ), "RoleId", BelongType.HasOne )]
        public Role Role
        {
            get { return UserRole; }
            set { UserRole = value; }
        }        

        [OrmTableField( "Name", SqlDbType.VarChar, 50, false )]
        [OrmLookUp]
        public string Name
        {
            get { return this._Name; }
            set { this._Name = value; }
        }

        [OrmTableField( "Login", SqlDbType.VarChar, 50, false )]
        [OrmLookUp]
        public string Login
        {
            get { return this._Login; }
            set { this._Login = value; }
        }

        [OrmTableField( "Password", SqlDbType.VarChar, 20, false )]
        [OrmLookUp]
        public string Password
        {
            get { return this._Password; }
            set { this._Password = value; }
        }

        [OrmTableField( "XML", SqlDbType.NText, true ) ]
        public string XML
        {
            get { return this._XML; }
            set { this._XML = value; }
        }

        [OrmTableField( "Approved", SqlDbType.Bit, true )]
        [OrmLookUp]
        public bool? Approved
        {
            get { return this._Approved; }
            set { this._Approved = value; }
        }

        [OrmTableField( "Deleted", SqlDbType.Bit, true )]
        [OrmLookUp]
        public bool? Deleted
        {
            get { return this._Deleted; }
            set { this._Deleted = value; }
        }

        [OrmTableField( "DateCreated", SqlDbType.DateTime, -1, false, "getdate()" )]
        public DateTime? DateCreated
        {
            get { return this._DateCreated; }
            set { this._DateCreated = value; }
        }
        #endregion
        
        public User( )
        {
            this.id_User = null;
            this._Name = string.Empty;
            this._Login = string.Empty;
            this._Password = string.Empty;
            this._XML = string.Empty;
            this._Approved = null;
            this._Deleted = false;
            this._DateCreated = null;
            this.UserRole = null;
        }
    }
}